package cn.edu.hpu.jie.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import cn.edu.hpu.jie.entity.Log;
import cn.edu.hpu.jie.util.RowMapping;
import cn.edu.hpu.jie.util.VoteDB;

public class LogDao {
	private VoteDB<Log> db = new VoteDB<Log>();
	
	private class LogMapping implements RowMapping<Log>{

		public Log getMapping(ResultSet rs) throws SQLException {
			Log l = new Log();
			l.setId(rs.getInt("id"));
			l.setEventid(rs.getInt("eventid"));
			l.setTime(rs.getString("time"));
			l.setDesc(rs.getString("desc"));
			l.setLoginid(rs.getInt("loginid"));
			return l;
		}
	}
	
	public int insertLog(Log l) {
		String sql = "INSERT INTO t_log(eventid, `time`, `desc`, loginid) VALUES (?, ?, ?, ?)";
		return db.updateData(sql, l.getEventid(), l.getTime(), l.getDesc(), l.getLoginid());
	}
	
	//获取所有的操作记录，需要和t_login表联查
	/*public List<Log> getAll() {
		String sql = "SELECT id, eventid, `time`, `desc`, loginid FROM t_log";
		return null;
	}*/
}
